package com.holly.common_view.adapter;

import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.holly.common.utils.L;

import java.util.ArrayList;
import java.util.List;

/**
 * adapter基类
 * 1.设置list和获取list的方法
 *
 * @author Joey Huang（QQ:273179370）
 * @created 2016/8/26
 */
public abstract class BaseAdapter<Bean> extends RecyclerView.Adapter implements IAdapter<Bean> {
    protected final String TAG = L.createTag(this);
    //当前界面显示所使用的List
    protected final List<Bean> mList = new ArrayList<Bean>();

    @Override
    public void setList(@Nullable List<Bean> list) {
        mList.clear();
        if (list != null) {
            mList.addAll(list);
            L.d(TAG, "setList.size = " + mList.size());
        } else {
            L.d(TAG, "setList: size = 0");
        }
    }

    @Override
    public List<Bean> getList() {
        List list = new ArrayList();
        list.addAll(mList);
        L.d(TAG, "getList.size = " + list.size());
        return list;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof BaseHolder) {
            BaseHolder baseHolder= (BaseHolder) holder;
            baseHolder.mPosition=position;
            baseHolder.bean=mList.get(position);
        }
        L.v(TAG,"onBindViewHolder position = "+ position);
    }
}
